﻿
/* 
 * Since 2008 - 2012
 */
package com.hh.bss.project.controller;

import static com.hh.bss.util.extjs.JsonHelper.outJson;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;


import com.hh.bss.base.*;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.project.dao.*;
import com.hh.bss.project.entity.*;
import com.hh.bss.project.service.*;
import com.hh.bss.project.vo.query.*;
import com.hh.bss.util.*;
import com.hh.bss.util.extjs.ExtJsPageHelper;
import com.hh.bss.util.extjs.ListRange;

import java.util.*;





@Controller
public class ContractJobCvJdController extends BaseSpringController{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	private ContractJobCvJdService contractJobCvJdService;
	
	private ContractJobCvJd contractJobCvJd;
	java.lang.Integer id = null;
	private String[] items;

	
	
	/** 通过spring自动注入 */
	public void setContractJobCvJdServiceImpl(ContractJobCvJdService service) {
		this.contractJobCvJdService = service;
	}	
	
	
	
	public void setId(java.lang.Integer val) {
		this.id = val;
	}

	public void setItems(String[] items) {
		this.items = items;
	}



	/**
	 * ExtGrid使用
	 * 列表
	 * @throws IOException
	 */
	public void list(HttpServletRequest request,HttpServletResponse response,ContractJobCvJdQuery contractJobCvJdQuery) throws IOException
	{
		PageRequest<Map> pr = ExtJsPageHelper.createPageRequestForExtJs(request, DEFAULT_SORT_COLUMNS);
		Page page = contractJobCvJdService.findPage(contractJobCvJdQuery);
		
		List<ContractJobCvJd> ContractJobCvJdlist = (List) page.getResult();
		ListRange<ContractJobCvJd> resultList = new ListRange<ContractJobCvJd>();
		resultList.setRows(ContractJobCvJdlist);
		resultList.setTotal(page.getTotalCount());
		resultList.setMessage("ok");
		resultList.setSuccess(true);
		outJson(response,resultList);
	}
	public void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
		Map<String, Object> result = new HashMap<String, Object>();
		String id = request.getParameter("id");
		if (StringUtils.isNotEmpty(id)) {
			result.put("failure", true);
			result.put("msg", "参数非法!");
		}
		try {
			ContractJobCvJd data = (ContractJobCvJd) contractJobCvJdService.getById(Integer.parseInt(id));
			if (data != null) {
				result.put("data", data);
				result.put("success", true);
				result.put("msg", "成功!");
			}

		} catch (Exception e) {
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(response, result);
	}
	public String managerPage(HttpServletRequest request, HttpServletResponse response) throws IOException {
		
		return "forward:/jsp/project/contractJobCvJd/contractJobCvJdPage.jsp";
			
	 }
	/**
	 * extGrid保存
	 * @throws IOException
	 */
	public void save(HttpServletRequest request,HttpServletResponse response,ContractJobCvJd contractJobCvJd) throws IOException
	{
		Map<String, Object> result = new HashMap<String, Object>();
		try
		{
                        //设置创建用户和创建时间
			com.hh.bss.auth.client.OnlineManager onlineManager=super.getOnlineManager(request, response);
			if (onlineManager!=null){
					com.hh.bss.auth.client.OnlineUser onlineUser=onlineManager.getOnlineUser();
					if (onlineUser!=null&&com.hh.bss.util.BeanUtils.isExistsProperty(ContractJobCvJd.class,"creator")) {
						try{com.hh.bss.util.BeanUtils.setProperty(contractJobCvJd,"creator",onlineUser.getUsername());}catch(Exception ex){}
					}
				}
							
			if (com.hh.bss.util.BeanUtils.isExistsProperty(ContractJobCvJd.class,"createDt")) {
					try{com.hh.bss.util.BeanUtils.setProperty(contractJobCvJd,"createDt",new Date());}catch(Exception ex){}
				}

			contractJobCvJdService.save(contractJobCvJd);
			result.put("success", true);
			result.put("msg", "添加成功!");
		}
		catch (Exception e)
		{
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(response,result);
	}
	
	/**
	 * extGrid修改
	 * @throws IOException
	 */
	public void update(HttpServletRequest request,HttpServletResponse response,ContractJobCvJd contractJobCvJd) throws IOException
	{
		Map<String, Object> result = new HashMap<String, Object>();
		try
		{
                        ContractJobCvJd oldcontractJobCvJd = (ContractJobCvJd)contractJobCvJdService.getById(contractJobCvJd.getId());
                         
			bind(request,oldcontractJobCvJd);
                        //设置修改用户和修改时间 
                        com.hh.bss.auth.client.OnlineManager onlineManager=super.getOnlineManager(request, response);
			if (onlineManager!=null){
					com.hh.bss.auth.client.OnlineUser onlineUser=onlineManager.getOnlineUser();
					if (onlineUser!=null&&com.hh.bss.util.BeanUtils.isExistsProperty(ContractJobCvJd.class,"modifier")) {
						try{com.hh.bss.util.BeanUtils.setProperty(oldcontractJobCvJd,"modifier",onlineUser.getUsername());}catch(Exception ex){}
					}
				}
							
			if (com.hh.bss.util.BeanUtils.isExistsProperty(ContractJobCvJd.class,"modifiedDt")) {
					try{com.hh.bss.util.BeanUtils.setProperty(oldcontractJobCvJd,"modifiedDt",new Date());}catch(Exception ex){}
				}


			contractJobCvJdService.update(oldcontractJobCvJd);
			result.put("success", true);
			result.put("msg", "修改成功!");
		}
		catch (Exception e)
		{
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(response,result);
	}
	
	/**
	 * extGrid删除
	 * @throws IOException
	 */
	public void delete(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		String ids = request.getParameter("ids");
		String[] idarray = ids.split(",");
		Map<String, Object> result = new HashMap<String, Object>();
		try
		{
			for (int i = 0; i < idarray.length; i++)
			{
				java.lang.Integer id = new java.lang.Integer((String)idarray[i]);
				contractJobCvJdService.removeById(id);
			}
			result.put("success", true);
			result.put("msg", "删除成功");
		}
		catch (Exception e)
		{
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(response,result);
	}
	
}
